<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>药品订单API测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        button {
            padding: 10px 20px;
            margin: 5px;
            background-color: #1890ff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #40a9ff;
        }
        .result {
            margin-top: 10px;
            padding: 10px;
            background-color: #f5f5f5;
            border-radius: 4px;
            white-space: pre-wrap;
            font-family: monospace;
            max-height: 300px;
            overflow-y: auto;
        }
        input {
            padding: 8px;
            margin: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 200px;
        }
    </style>
</head>
<body>
    <h1>药品订单API测试</h1>
    
    <div class="test-section">
        <h3>1. 获取药品订单列表</h3>
        <button onclick="testGetOrderList()">获取订单列表</button>
        <div id="orderListResult" class="result"></div>
    </div>

    <div class="test-section">
        <h3>2. 获取药品订单详情</h3>
        <input type="number" id="orderId" placeholder="输入订单ID" value="30">
        <button onclick="testGetOrderDetail()">获取订单详情</button>
        <div id="orderDetailResult" class="result"></div>
    </div>

    <div class="test-section">
        <h3>3. 获取物流公司列表</h3>
        <button onclick="testGetLogisticsCompanies()">获取物流公司</button>
        <div id="logisticsResult" class="result"></div>
    </div>

    <div class="test-section">
        <h3>4. 订单发货测试</h3>
        <input type="number" id="shipOrderId" placeholder="订单ID" value="30">
        <select id="logisticsCompany">
            <option value="">选择物流公司</option>
            <option value="SF">顺丰快递</option>
            <option value="JD">京东物流</option>
            <option value="DB">德邦快递</option>
            <option value="YT">圆通快递</option>
            <option value="ST">申通快递</option>
            <option value="ZT">中通快递</option>
        </select>
        <input type="text" id="trackingNumber" placeholder="物流单号" value="TEST123456">
        <button onclick="testShipOrder()">订单发货</button>
        <div id="shipResult" class="result"></div>
    </div>

    <div class="test-section">
        <h3>5. 确认收货测试</h3>
        <input type="number" id="confirmOrderId" placeholder="订单ID" value="30">
        <button onclick="testConfirmReceipt()">确认收货</button>
        <div id="confirmResult" class="result"></div>
    </div>

    <script>
        const API_BASE = 'http://localhost:5242/api';

        async function makeRequest(url, options = {}) {
            try {
                const response = await fetch(url, {
                    headers: {
                        'Content-Type': 'application/json',
                        ...options.headers
                    },
                    ...options
                });
                const data = await response.json();
                return { success: true, data };
            } catch (error) {
                return { success: false, error: error.message };
            }
        }

        function displayResult(elementId, result) {
            const element = document.getElementById(elementId);
            if (result.success) {
                element.textContent = JSON.stringify(result.data, null, 2);
            } else {
                element.textContent = `错误: ${result.error}`;
            }
        }

        async function testGetOrderList() {
            const result = await makeRequest(`${API_BASE}/MedicalOrder/list?PageIndex=1&PageSize=10`);
            displayResult('orderListResult', result);
        }

        async function testGetOrderDetail() {
            const orderId = document.getElementById('orderId').value;
            const result = await makeRequest(`${API_BASE}/MedicalOrder/detail/${orderId}`);
            displayResult('orderDetailResult', result);
        }

        async function testGetLogisticsCompanies() {
            const result = await makeRequest(`${API_BASE}/MedicalOrderWrite/logistics-companies`);
            displayResult('logisticsResult', result);
        }

        async function testShipOrder() {
            const orderId = document.getElementById('shipOrderId').value;
            const logisticsCompany = document.getElementById('logisticsCompany').value;
            const trackingNumber = document.getElementById('trackingNumber').value;
            
            const result = await makeRequest(`${API_BASE}/MedicalOrderWrite/ship`, {
                method: 'POST',
                body: JSON.stringify({
                    orderId: parseInt(orderId),
                    logisticsCompany: logisticsCompany,
                    trackingNumber: trackingNumber
                })
            });
            displayResult('shipResult', result);
        }

        async function testConfirmReceipt() {
            const orderId = document.getElementById('confirmOrderId').value;
            
            const result = await makeRequest(`${API_BASE}/MedicalOrderWrite/confirm-receipt`, {
                method: 'POST',
                body: JSON.stringify({
                    orderId: parseInt(orderId)
                })
            });
            displayResult('confirmResult', result);
        }

        // 页面加载时自动获取物流公司列表
        window.onload = function() {
            testGetLogisticsCompanies();
        };
    </script>
</body>
</html> 